package com.cpkso.yzx.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/**
 * User双向ManyToMany 可能需要role
 * 
 * @author wrzhxy@qq.com
 * @date 2017年11月10日
 */
@Entity
@Table(name="t_role")
public class Role {
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private Long id;
	private String name;
	private String brief;
	@ManyToMany(mappedBy="roles")
	private Set<User> users = new HashSet<>();
	@ManyToMany
	@JoinTable(name="t_role_request", joinColumns=@JoinColumn(name="roleid")
	, inverseJoinColumns=@JoinColumn(name="reqid"))
	private Set<Request> requests = new HashSet<>();
	
	public Role() {
	}
	/**
	 * no id
	 * @param name
	 * @param brief
	 * @param users
	 * @param requests
	 */
	public Role(String name, String brief, Set<User> users, Set<Request> requests) {
		this.name = name;
		this.brief = brief;
		this.users = users;
		this.requests = requests;
	}
	public Role(long id) {
		this.id = id;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = "".equals(brief) ? null : name;
	}
	public String getBrief() {
		return brief;
	}
	public void setBrief(String brief) {
		this.brief = "".equals(brief) ? null : brief;
	}
	public Set<User> getUsers() {
		return users;
	}
	public void setUsers(Set<User> users) {
		this.users = users;
	}
	public Set<Request> getRequests() {
		return requests;
	}
	public void setRequests(Set<Request> requests) {
		this.requests = requests;
	}
	
}
